{
 "metadata": {
  "language": "Julia",
  "name": "",
  "signature": "sha256:4526fbc78f0271590c8440dc825aecfd5f737f9e9ce1cca29f8d7a3b4c1db99a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "# Matrix Depot \n",
      "\n",
      "A test matrix collection for Julia. \n",
      "\n",
      "1. Install\n",
      "2. Usage\n",
      "3. Examples\n",
      "4. User Defined Properties\n",
      "5. More Examples"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## 1. Install"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "To install the package, type"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Pkg.add(\"MatrixDepot\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## 2. Usage\n",
      "\n",
      "First load the package:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "using MatrixDepot"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The only function will be exported is `matrixdepot`."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "? matrixdepot"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stderr",
       "text": [
        "INFO: Loading help data...\n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "matrixdepot (generic function with 17 methods)\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Every matrix in the collection is represented by a string `matrix_name`, for example, the Cauchy matrix is represented by `\"cauchy\"` and the Hilbert matrix is represented by `\"hilb\"`. \n",
      "\n",
      "The properties of the matrices in the collection are also symbolized by strings `property_name`. For example, the class of the symmetric matrices is symbolized by `\"symmetric\"`."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "* `matrixdepot()` returns a list of all the matrices in the collection.\n",
      "\n",
      "* `matrixdepot(matrix_name, p1, p2, ...)` returns a matrix specified by the query string `matrix_name`. `p1, p2, ...` are input parameters depending on `matrix_name`. \n",
      "\n",
      "* `matrixdepot(matrix_name)` returns the parameter options and the properties of `matrix_name`.\n",
      "\n",
      "* `matrixdepot(property_name)` returns a list of matrices with the property `property_name`.\n",
      "\n",
      "* `matrixdepot(prop1, prop2, prop3,...)` returns a list of matrices with properties `prop1`, `prop2`, `prop3` etc."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can define our own properties using the macro `@addproperty`\n",
      "\n",
      "- `@addproperty property_name = [\"matrix1\", \"matrix2\", \"matrix3\"]`\n",
      "\n",
      "and remove a defined property using the macro `@rmproperty`\n",
      "\n",
      "- `@rmproperty property_name`\n",
      "\n",
      "See below for examples."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## 3. Examples"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "To see all the matrices in the collection, type"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "          | symmetric |  inverse  | ill-cond  |  pos-def  |  eigen    |"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "      vand|           |     *     |     *     |           |           |\n",
        "     frank|           |           |     *     |           |     *     |\n",
        "     minij|     *     |     *     |           |     *     |     *     |\n",
        "   clement|     *     |     *     |           |           |     *     |\n",
        "   tridiag|     *     |     *     |     *     |     *     |     *     |\n",
        "    circul|     *     |           |           |     *     |     *     |\n",
        "  dingdong|     *     |           |           |           |     *     |\n",
        "  hadamard|           |     *     |           |           |     *     |\n",
        "     moler|     *     |     *     |     *     |     *     |           |\n",
        "     invol|           |     *     |     *     |           |     *     |\n",
        "   fiedler|     *     |     *     |           |           |     *     |\n",
        "  binomial|           |           |           |           |           |\n",
        "    lehmer|     *     |     *     |           |     *     |           |\n",
        "   invhilb|     *     |     *     |     *     |     *     |           |\n",
        "    lotkin|           |     *     |     *     |           |     *     |\n",
        "      triw|           |     *     |     *     |           |           |\n",
        "     magic|           |     *     |           |           |           |\n",
        "     kahan|           |     *     |     *     |           |           |\n",
        "    pascal|     *     |     *     |     *     |     *     |     *     |\n",
        "  chebspec|           |           |           |           |     *     |\n",
        "      hilb|     *     |     *     |     *     |     *     |           |\n",
        "    cauchy|     *     |     *     |     *     |     *     |           |\n",
        "       pei|     *     |     *     |     *     |     *     |           |\n",
        "    parter|           |           |           |           |     *     |\n",
        "  forsythe|           |     *     |     *     |           |     *     |\n",
        "     grcar|           |           |           |           |     *     |\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The meanings of the column heading is as follows:\n",
      "\n",
      "* `\"symmetric\"`: the matrix is symmetric for some parameter values.\n",
      "\n",
      "* `\"inverse\"`: the inverse of the matrix is known explicitly.\n",
      "\n",
      "* `\"ill-cond\"`: the matrix is ill-conditioned for some parameter values.\n",
      "\n",
      "* `\"pos-def\"`: the matrix is symmetric positive definite for some parameter values.\n",
      "\n",
      "* `\"eigen\"`: the eigensystem of the matrix has some known results (explicit formulas for eigenvalues, eigenvectors, bounds of eigenvalues, etc)."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can generate a Hilbert matrix of size 4 by typing"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"hilb\", 4)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "4x4 Array{Float64,2}:\n",
        " 1.0       0.5       0.333333  0.25    \n",
        " 0.5       0.333333  0.25      0.2     \n",
        " 0.333333  0.25      0.2       0.166667\n",
        " 0.25      0.2       0.166667  0.142857"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "and generate a circul matrix of size 5 by "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"circul\", 5)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "5x5 Array{Float64,2}:\n",
        " 1.0  2.0  3.0  4.0  5.0\n",
        " 5.0  1.0  2.0  3.0  4.0\n",
        " 4.0  5.0  1.0  2.0  3.0\n",
        " 3.0  4.0  5.0  1.0  2.0\n",
        " 2.0  3.0  4.0  5.0  1.0"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can type the matrix name to see the parameter options or matrix properties. "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"hilb\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Hilbert matrix: \n",
        "             \n",
        " Input options: \n",
        "             \n",
        " (type), dim: the dimension of the matrix\n",
        "             \n",
        " (type), row_dim, col_dim: the row and column dimension \n",
        "             \n",
        " ['inverse', 'ill-cond', 'symmetric', 'pos-def']\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"hadamard\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Hadamard matrix: \n",
        "             \n",
        " Input options: \n",
        "             \n",
        " (type), dim: the dimension of the matrix, n is a power of 2 \n",
        "             \n",
        " ['inverse', 'orthogonal', 'eigen']\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "From the information given, we notice that we can create\n",
      "a 4-by-6 rectangular Hilbert matrix by"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"hilb\", 4, 6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "4x6 Array{Float64,2}:\n",
        " 1.0       0.5       0.333333  0.25      0.2       0.166667\n",
        " 0.5       0.333333  0.25      0.2       0.166667  0.142857\n",
        " 0.333333  0.25      0.2       0.166667  0.142857  0.125   \n",
        " 0.25      0.2       0.166667  0.142857  0.125     0.111111"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can also specify the data type"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"hilb\", Float16, 5, 3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 9,
       "text": [
        "5x3 Array{Float16,2}:\n",
        " 1.0      0.5      0.33325\n",
        " 0.5      0.33325  0.25   \n",
        " 0.33325  0.25     0.19995\n",
        " 0.25     0.19995  0.16663\n",
        " 0.19995  0.16663  0.14282"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "By inputting a matrix name, we can see what properties that matrix have. Conversely, if we input a property (or properties),\n",
      "we can see all the matrices (in the collection) having that property (or properties). "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"symmetric\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "12-element Array{ASCIIString,1}:\n",
        " \"hilb\"    \n",
        " \"cauchy\"  \n",
        " \"circul\"  \n",
        " \"dingdong\"\n",
        " \"invhilb\" \n",
        " \"moler\"   \n",
        " \"pascal\"  \n",
        " \"pei\"     \n",
        " \"clement\" \n",
        " \"fiedler\" \n",
        " \"minij\"   \n",
        " \"tridiag\" "
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"symmetric\", \"ill-cond\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 11,
       "text": [
        "7-element Array{ASCIIString,1}:\n",
        " \"hilb\"   \n",
        " \"cauchy\" \n",
        " \"invhilb\"\n",
        " \"moler\"  \n",
        " \"pascal\" \n",
        " \"pei\"    \n",
        " \"tridiag\""
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"inverse\", \"ill-cond\", \"symmetric\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "7-element Array{ASCIIString,1}:\n",
        " \"hilb\"   \n",
        " \"cauchy\" \n",
        " \"invhilb\"\n",
        " \"moler\"  \n",
        " \"pascal\" \n",
        " \"pei\"    \n",
        " \"tridiag\""
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Given a property, we can loop through all the matrices having this property"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Multiply all matrices of the class \"symmetric\" and \"ill-cond\" and \"inverse\"\n",
      "A = eye(4)\n",
      "print(\"Identity matrix\")\n",
      "for mat in intersect(matrixdepot(\"symmetric\"), matrixdepot(\"ill-cond\"), matrixdepot(\"inverse\")) \n",
      "    print(\" x $mat matrix\")\n",
      "    A = A * full(matrixdepot(mat, 4))    \n",
      "end\n",
      "println(\" =\")\n",
      "A    "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Identity matrix x hilb matrix"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " x cauchy matrix x invhilb matrix x moler matrix x pascal matrix x pei matrix x tridiag matrix =\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 15,
       "text": [
        "4x4 Array{Float64,2}:\n",
        " 153.12    -11.919    -15.4345   296.937\n",
        " 109.896    -8.91857  -11.5976   214.433\n",
        "  86.7524   -7.15714   -9.32857  169.702\n",
        "  71.9139   -5.98707   -7.81497  140.876"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The loop above can also be written as "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "A = eye(4)\n",
      "print(\"Identity matrix\")\n",
      "for mat in matrixdepot(\"symmetric\", \"ill-cond\", \"inverse\")\n",
      "    print(\" x $mat matrix\")\n",
      "    A = A * full(matrixdepot(mat, 4))\n",
      "end\n",
      "println(\" =\")\n",
      "A"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Identity matrix x hilb matrix"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " x cauchy matrix x invhilb matrix x moler matrix x pascal matrix x pei matrix x tridiag matrix =\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 16,
       "text": [
        "4x4 Array{Float64,2}:\n",
        " 153.12    -11.919    -15.4345   296.937\n",
        " 109.896    -8.91857  -11.5976   214.433\n",
        "  86.7524   -7.15714   -9.32857  169.702\n",
        "  71.9139   -5.98707   -7.81497  140.876"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## 4. User Defined Properties"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can define properties in MatrixDepot. Since each property in Matrix Depot is a list of strings, you can simply do, for example,"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "spd = matrixdepot(\"symmetric\", \"pos-def\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 2,
       "text": [
        "10-element Array{ASCIIString,1}:\n",
        " \"hilb\"   \n",
        " \"cauchy\" \n",
        " \"circul\" \n",
        " \"invhilb\"\n",
        " \"moler\"  \n",
        " \"pascal\" \n",
        " \"pei\"    \n",
        " \"minij\"  \n",
        " \"tridiag\"\n",
        " \"lehmer\" "
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "myprop = [\"lehmer\", \"cauchy\", \"hilb\"]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "3-element Array{ASCIIString,1}:\n",
        " \"lehmer\"\n",
        " \"cauchy\"\n",
        " \"hilb\"  "
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Then use it in your tests like"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "for matrix in myprop\n",
      "    A = matrixdepot(matrix, 6)\n",
      "    L, U, p = lu(A) #LU factorization\n",
      "    err = norm(A[p,:] - L*U, 1) # 1-norm error\n",
      "    println(\"1-norm error for $matrix matrix is \", err)\n",
      "end    "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1-norm error for lehmer matrix is 1"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        ".1102230246251565e-16\n",
        "1-norm error for cauchy matrix is 5.551115123125783e-17\n",
        "1-norm error for hilb matrix is 2.7755575615628914e-17\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "To add a property permanently for future use, we put the macro `@addproperty` at the beginning."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "@addproperty myfav = [\"lehmer\", \"cauchy\", \"hilb\"]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 2,
       "text": [
        "87"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "@addproperty spd = matrixdepot(\"symmetric\", \"pos-def\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "195"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We need to **restart** Julia to see the changes. Type "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "          | symmetric |  inverse  | ill-cond  |  pos-def  |  eigen    |"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "      vand|           |     *     |     *     |           |           |\n",
        "     frank|           |           |     *     |           |     *     |\n",
        "     minij|     *     |     *     |           |     *     |     *     |\n",
        "   clement|     *     |     *     |           |           |     *     |\n",
        "   tridiag|     *     |     *     |     *     |     *     |     *     |\n",
        "    circul|     *     |           |           |     *     |     *     |\n",
        "  dingdong|     *     |           |           |           |     *     |\n",
        "  hadamard|           |     *     |           |           |     *     |\n",
        "     moler|     *     |     *     |     *     |     *     |           |\n",
        "     invol|           |     *     |     *     |           |     *     |\n",
        "   fiedler|     *     |     *     |           |           |     *     |\n",
        "  binomial|           |           |           |           |           |\n",
        "    lehmer|     *     |     *     |           |     *     |           |\n",
        "   invhilb|     *     |     *     |     *     |     *     |           |\n",
        "    lotkin|           |     *     |     *     |           |     *     |\n",
        "      triw|           |     *     |     *     |           |           |\n",
        "     magic|           |     *     |           |           |           |\n",
        "     kahan|           |     *     |     *     |           |           |\n",
        "    pascal|     *     |     *     |     *     |     *     |     *     |\n",
        "  chebspec|           |           |           |           |     *     |\n",
        "      hilb|     *     |     *     |     *     |     *     |           |\n",
        "    cauchy|     *     |     *     |     *     |     *     |           |\n",
        "       pei|     *     |     *     |     *     |     *     |           |\n",
        "  forsythe|           |     *     |     *     |           |     *     |\n",
        "     grcar|           |           |           |           |     *     |\n",
        "\n",
        "New Properties:\n",
        "\n",
        "spd = [ hilb, cauchy, circul, invhilb, moler, pascal, pei, minij, tridiag, lehmer, ] \n",
        "\n",
        "myfav = [ lehmer, cauchy, hilb, ] \n",
        "\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Notice new defined properties have been included. We can use them as "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot(\"myfav\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "3-element Array{ASCIIString,1}:\n",
        " \"lehmer\"\n",
        " \"cauchy\"\n",
        " \"hilb\"  "
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "We can remove a property using the macro `@rmproperty`. As before, we need to **restart** Julia to see the changes."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "@rmproperty myfav"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "153"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "matrixdepot()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "          | symmetric |  inverse  | ill-cond  |  pos-def  |  eigen    |"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "      vand|           |     *     |     *     |           |           |\n",
        "     frank|           |           |     *     |           |     *     |\n",
        "     minij|     *     |     *     |           |     *     |     *     |\n",
        "   clement|     *     |     *     |           |           |     *     |\n",
        "   tridiag|     *     |     *     |     *     |     *     |     *     |\n",
        "    circul|     *     |           |           |     *     |     *     |\n",
        "  dingdong|     *     |           |           |           |     *     |\n",
        "  hadamard|           |     *     |           |           |     *     |\n",
        "     moler|     *     |     *     |     *     |     *     |           |\n",
        "     invol|           |     *     |     *     |           |     *     |\n",
        "   fiedler|     *     |     *     |           |           |     *     |\n",
        "  binomial|           |           |           |           |           |\n",
        "    lehmer|     *     |     *     |           |     *     |           |\n",
        "   invhilb|     *     |     *     |     *     |     *     |           |\n",
        "    lotkin|           |     *     |     *     |           |     *     |\n",
        "      triw|           |     *     |     *     |           |           |\n",
        "     magic|           |     *     |           |           |           |\n",
        "     kahan|           |     *     |     *     |           |           |\n",
        "    pascal|     *     |     *     |     *     |     *     |     *     |\n",
        "  chebspec|           |           |           |           |     *     |\n",
        "      hilb|     *     |     *     |     *     |     *     |           |\n",
        "    cauchy|     *     |     *     |     *     |     *     |           |\n",
        "       pei|     *     |     *     |     *     |     *     |           |\n",
        "  forsythe|           |     *     |     *     |           |     *     |\n",
        "     grcar|           |           |           |           |     *     |\n",
        "\n",
        "New Properties:\n",
        "\n",
        "spd = [ hilb, cauchy, circul, invhilb, moler, pascal, pei, minij, tridiag, lehmer, ] \n",
        "\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## 5. More Examples"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "An interesting test matrix is magic square. It can be generated as "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "M = matrixdepot(\"magic\", 5)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 16,
       "text": [
        "5x5 Array{Int64,2}:\n",
        " 17  24   1   8  15\n",
        " 23   5   7  14  16\n",
        "  4   6  13  20  22\n",
        " 10  12  19  21   3\n",
        " 11  18  25   2   9"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sum(M,1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 17,
       "text": [
        "1x5 Array{Int64,2}:\n",
        " 65  65  65  65  65"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sum(M,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 18,
       "text": [
        "5x1 Array{Int64,2}:\n",
        " 65\n",
        " 65\n",
        " 65\n",
        " 65\n",
        " 65"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "sum(diag(M))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 19,
       "text": [
        "65"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "p = [5:-1:1]\n",
      "sum(diag(M[:,p]))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 20,
       "text": [
        "65"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Pascal Matrix can be generated as "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "P = matrixdepot(\"pascal\", 6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 21,
       "text": [
        "6x6 Array{Int64,2}:\n",
        " 1  1   1   1    1    1\n",
        " 1  2   3   4    5    6\n",
        " 1  3   6  10   15   21\n",
        " 1  4  10  20   35   56\n",
        " 1  5  15  35   70  126\n",
        " 1  6  21  56  126  252"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Notice the Cholesky factor of the Pascal matrix has Pascal's triangle rows."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "chol(P)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 22,
       "text": [
        "6x6 Array{Float64,2}:\n",
        " 1.0  1.0  1.0  1.0  1.0   1.0\n",
        " 0.0  1.0  2.0  3.0  4.0   5.0\n",
        " 0.0  0.0  1.0  3.0  6.0  10.0\n",
        " 0.0  0.0  0.0  1.0  4.0  10.0\n",
        " 0.0  0.0  0.0  0.0  1.0   5.0\n",
        " 0.0  0.0  0.0  0.0  0.0   1.0"
       ]
      }
     ],
     "prompt_number": 22
    }
   ],
   "metadata": {}
  }
 ]
}